SUBDIRS = icons favicon

gpyp_icons = \
gpyp
search_icon_names = \
search_normal \
search_migemo \
search_original \
search_regex
icon_16_names = peercast yp4g

gpyp_icon_files = $(gpyp_icons:=.png)

pixmaps_DATA = $(gpyp_icons:=.png)
pkgpixmaps_16_DATA = $(icon_16_names:=.png)
pkgpixmaps_scalable_DATA = $(gpyp_icons:=.svg)

gpyp_icon_headers = $(gpyp_icons:=_16.h) $(gpyp_icons:=_22.h) $(gpyp_icons:=_32.h) $(gpyp_icons:=_48.h)
search_icon_headers = $(search_icon_names:=_16.h) $(search_icon_names:=_22.h) $(search_icon_names:=_32.h)

BUILT_SOURCES = $(gpyp_icon_headers) $(search_icon_headers) \
icon_decl.h icon_impl.cpp icon_incl.h icon_add_builtin_icon.cpp icon_builtin_icon_list.h

.png.h:
	gdk-pixbuf-csource --raw --name=icon_$* $< > $@

$(gpyp_icon_files): $(gpyp_icons:=.svg) Makefile
	@fn=$(@:.png=);rsvg-convert $$fn.svg -w 48 -o $@
$(search_icon_headers): $(search_icon_names:=.svg) Makefile
	@fn=$(@:.h=);rsvg-convert $${fn%_*}.svg -w $${fn##*_} -o $(@:.h=.png)
	gdk-pixbuf-csource --raw --name=icon_$(@:.h=) $(@:.h=.png) > $@
	rm $(@:.h=.png)
$(gpyp_icon_headers): $(gpyp_icons:=.svg) Makefile
	@fn=$(@:.h=);rsvg-convert $${fn%_*}.svg -w $${fn##*_} -o $(@:.h=.png)
	gdk-pixbuf-csource --raw --name=icon_$(@:.h=) $(@:.h=.png) > $@
	rm $(@:.h=.png)
icon_decl.h: Makefile
	rm -f $@
	@for n in $(gpyp_icons) $(icon_16_names) $(search_icon_names);do name=$$(echo "$$n" | tr "[a-z]" "[A-Z]");echo "static const char *$$name;" >> $@;done
	echo "#include \"icons/$@\"" >> $@;
	echo "#include \"favicon/$@\"" >> $@;
icon_impl.cpp: Makefile
	rm -f $@
	@for n in $(gpyp_icons) $(icon_16_names) $(search_icon_names);do name=$$(echo "$$n" | tr "[a-z]" "[A-Z]");echo "const char *IconManager::$$name = \"$$n\";" >> $@;done
	echo "#include \"icons/$@\"" >> $@;
	echo "#include \"favicon/$@\"" >> $@;
icon_incl.h: Makefile
	rm -f $@
	@for h in $(gpyp_icon_headers) $(search_icon_headers);do echo "#include \"$$h\"" >> $@;done
icon_add_builtin_icon.cpp: Makefile
	rm -f $@
	@for h in $(gpyp_icon_headers) $(search_icon_headers);do fn=$${h%.h};name=$${fn%_*};size=$${fn##*_};echo "Gtk::IconTheme::add_builtin_icon(\"$$name\",$$size,Gdk::Pixbuf::create_from_inline(sizeof(icon_$$fn),icon_$$fn));" >> $@;done
icon_builtin_icon_list.h: Makefile
	rm -f $@
	@for n in $(gpyp_icons) $(icon_16_names) $(search_icon_names);do name=$$(echo "$$n" | tr "[a-z]" "[A-Z]");echo "$$name," >> $@;done
	echo "#include \"favicon/$@\"" >> $@;
	echo "#include \"icons/$@\"" >> $@;
	echo "NULL" >> $@;

EXTRA_DIST = gpyp.svg $(icon_16_names:=.png) $(search_icon_names:=.svg)

CLEANFILES = $(gpyp_icon_files) $(BUILT_SOURCES)
